using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnGetData_Click(object sender, EventArgs e)
        {
            Rmvbediter.RMMF rmmf = new Rmvbediter.RMMF();
            rmmf.Load(@"R:\1.rmvb");
            StringBuilder sb = new StringBuilder();

            int index = 1; 
            int start = 0;

            Jillzhang.VideoCapture.FrameGrabber fg = new Jillzhang.VideoCapture.FrameGrabber();

            foreach (Rmvbediter.IndexDate id in rmmf.Index.KeyIndexs)
            {
                sb.AppendFormat("\"D:\\Program Files\\Real\\Helix Producer Plus\\RealMediaEditor\\rmeditor.exe\" -i \"1.rmvb\" -o \"o{0}.rmvb\" -s \"{1}\" -e \"{2}\"\r\n",
                    index++, GetTimeStr(start), GetTimeStr(id.timestamp));


                start = rmmf.GetBeforTimeSpan(id.timestamp);

                //start -= rmmf.GetBeforTimeSpan(id.timestamp);

                //Jillzhang.VideoCapture.FrameGrabber.SaveFrameFromVideo(@"R:\1.rmvb", id.timestamp / 1000.0, string.Format(@"R:\{0}.bmp", index));
            }

            textBox1.Text = sb.ToString();

            System.IO.File.WriteAllText(@"R:\run.bat", sb.ToString());

        }

        public string GetTimeStr(int timeSpan)
        {
            int sec = timeSpan / 1000;

            int min = sec / 60;

            int hero = sec / (60 * 60);

            min = (sec - (hero * 60 * 60)) / 60;
            sec = sec - (hero * 60 * 60) - min * 60;

            return string.Format("{0}:{1}:{2}.{3}", hero, min, sec, timeSpan % 1000);
        }
    }
}